import {defineStore} from "pinia";
import {ref, watch} from "vue";

export const useStore = defineStore('useStore', {
    state: () => ({

        togetherRoomInfo: ref ({
            togetherPlayMusicIndex: null,
            // null就默认喜欢歌单
            togetherPlayMusicSheet: null,
            togetherRoomId: '',
            // 播放状态默认是不播放
            togetherPlayStatus: false,
            // 歌曲进度
            togetherMusicPosition: 0
        }),

        otherUser: ref({
            avatar: 'src/assets/img/icon.png',
            account: '',
            username: '',
            exist: false
        })
    }),
    getters: {

    },

    actions: {
        resetTheWorld() {
            this.togetherRoomInfo = {
                togetherPlayMusicIndex: null,
                togetherPlayMusicSheet: null,
                togetherRoomId: null,
                togetherPlayStatus: false,
                togetherMusicPosition: 0
            };
            this.otherUser = {
                avatar: 'src/assets/img/icon.png',
                account: '',
                username: '',
                exist: false
            };
        }
    },
    persist: {
        enabled: true, // 开启缓存  默认会存储在本地localstorage
        storage: localStorage, // 缓存使用方式
        paths: ['otherUser.avatar', 'otherUser.account', 'otherUser.username', 'otherUser.exist',
        'togetherRoomInfo.togetherPlayMusicIndex', 'togetherRoomInfo.togetherPlayMusicSheet', 'togetherRoomInfo.togetherRoomId']
    }
})



